﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Windows.Forms;
using SyringeControl.ControlSamples;

namespace SyringeControl.Factories.Tests
{
    [TestFixture]
    public class Test_ActivatorControlFactory
    {
        IControlFactory factory = new ActivatorControlFactory();
        
        [TestCase(typeof(TextBox), Result=true)]
        [TestCase(typeof(UpperCaseTextBox), Result=true)]
        [TestCase(typeof(TextBoxBase), Result = false, Description="Can't instantiate abstract classes")]
        [TestCase(typeof(ICloneable), Result = false, Description="Can't instantiate interfaces")]
        [TestCase(typeof(SpellCheckingTextBox), Result = false, Description="Can't instantiate classes without default constructor")]
        public bool Allows_to_create_types_with_public_default_constructor(Type controlType)
        {
            return factory.IsValid(controlType);
        }

        [TestCase(typeof(TextBox), Result=typeof(TextBox))]
        [TestCase(typeof(UpperCaseTextBox), Result = typeof(UpperCaseTextBox))]
        [TestCase(typeof(TextBoxBase), ExpectedException=typeof(ArgumentException),  Description = "Can't instantiate abstract classes")]
        [TestCase(typeof(ICloneable), ExpectedException = typeof(ArgumentException), Description = "Can't instantiate interfaces")]
        [TestCase(typeof(SpellCheckingTextBox), ExpectedException = typeof(ArgumentException), Description = "Can't instantiate classes without default constructor")]
        public Type Creates_instances_of_given_Control_types(Type requestedType)
        {
            return factory.Create(requestedType).GetType();
        }

        [Test]
        public void Returns_null_for_null_type()
        {
            Assert.That(factory.Create(null), Is.Null);
        }
    }
}
